package com.sj.purchase.modules.purchase.repository;

import com.sj.purchase.modules.purchase.domain.Purchase;
import com.sj.purchase.modules.purchase.domain.PurchaseId;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;

/**
 * Created by icodebug on 17-5-25.
 */
public interface PurchaseRepository extends JpaRepository<Purchase,PurchaseId>{



    @Query( value = "select sum(sp.yesterday_sales) from stock_price sp where sp.purchase_sku_no = :skuNo and warehouse_enum=:warehouse and sp.purchase_create_date between :createDate and :endDate" , nativeQuery = true)
    Integer getThreeDaySales(@Param("createDate")String createDate,@Param("endDate")String endDate,@Param("skuNo") String skuNo,@Param("warehouse")String warehouse);

    Page<Purchase> findByIdCreateDate(Date createDate, Pageable pageable);

}
